package com.devehx.wallet.task;

import com.devehx.wallet.comm.CollectKit;
import com.devehx.wallet.comm.Const;
import com.devehx.wallet.comm.ERC20;
import com.devehx.wallet.comm.WalletKit;
import com.devehx.wallet.model.Dict;
import com.devehx.wallet.model.UserAddress;
import com.devehx.wallet.repository.DictDao;
import com.devehx.wallet.serviceimpl.RechargeService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.math.BigInteger;
import java.util.Objects;

@Slf4j
//@Component
public class CollectTask {

//    @Resource
//    private DictDao dictDao;
//
//    @Resource
//    private RechargeService rechargeService;
//
//
//
//    @Scheduled(fixedDelay = 60000)
//    public void collect() {
//        DictModel dict = getDict();
//        String collect = dict.getCollectAddress();
//        String wallet = dict.getWalletAddress();
//        String walletKey = dict.getWalletPrivateKey();
//        for (UserAddress userAddress : rechargeService.findAllAddress()) {
//            String address = userAddress.getAddress();
//            if (!CollectKit.isOk(address)) {
//                continue;
//            }
//            BigInteger balanceUsdt = WalletKit.getBalance(address, ERC20.USDT.address);
//            if (balanceUsdt.compareTo(Const.USDT_MIN_UNIT.toBigInteger()) < 0) {
//                log.warn("未达到归集数量");
//                //标识为暂时不归集
//                CollectKit.add(address);
//                continue;
//            }
//            BigInteger balanceEth = WalletKit.getBalance(address);
//            if (balanceEth.compareTo(Const.GAS_COLLECT) < 0) {
//                //转手续费
//                String tx = WalletKit.transfer(ERC20.ETH.address, wallet, walletKey, address, Const.GAS_COLLECT);
//                log.warn("用户账户USDT余额：{}，ETH余额：{}，ETH小于{}，转给用户手续费，交易哈希{}", balanceUsdt, balanceEth, Const.GAS_COLLECT, tx);
//                //标识为暂时不归集
//                CollectKit.add(address);
//                continue;
//            }
//            String tx = WalletKit.transfer(ERC20.USDT.address, address, userAddress.getPrivateKey(), collect, balanceUsdt);
//            log.warn("归集：数量{}个，交易哈希{}", balanceUsdt, tx);
//            //标识为暂时不归集
//            CollectKit.add(address);
//        }
//    }

}
